/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gestionedt.pools;

import gestionedt.models.Pool;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 * 
 */
public class PoolsForm extends org.apache.struts.action.ActionForm {
    
    private List<Pool> pools;
    
    private int idPool;
    
    private Pool pool;

    /**
     *
     */
    public PoolsForm() {
        super();
        this.pool = new Pool();
    }

    public int getIdPool() {
        return idPool;
    }

    public void setIdPool(int idPool) {
        this.idPool = idPool;
    }

    public Pool getPool() {
        return pool;
    }

    public void setPool(Pool pool) {
        this.pool = pool;
    }

    public List<Pool> getPools() {
        return pools;
    }

    public void setPools(List<Pool> pools) {
        this.pools = pools;
    }

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if(pool.getLibelle() == null || pool.getLibelle().trim().length() < 1)
            errors.add("pool.libelle", new ActionMessage("errors.required",
                                                         "Le champ libellé"));
        if(pool.getNbPrestMaxParPlage() < 1)
            errors.add("pool.nbPrestMax", new ActionMessage("errors.detail",
                                                            "Le nombre de prestations simultanées maximum " +
                                                            "doit être un nombre entier supérieur à 0."));
        return errors;
    }
}
